package com.weibo.controller.admin;

import com.weibo.entity.Blog;
import com.weibo.resp.BlogDetailAndCommentsResp;
import com.weibo.resp.BlogListItemResp;
import com.weibo.service.BlogService;
import com.weibo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/admin/blog")
public class AdminBlogController {

    @Autowired
    BlogService blogService;

    @Value("${file.upload-dir}")
    private String uploadDir;

    @GetMapping("/list")
    public ResponseResult getList(){
        HashMap<String,Object> param = new HashMap<>();
        List<BlogListItemResp> blogListItemResps = blogService.getList(param);
        return new ResponseResult(blogListItemResps);
    }

    @GetMapping("/one/{blogId}")
    public ResponseResult getOne(@PathVariable("blogId") int blogId){
        BlogDetailAndCommentsResp resp = blogService.getOne(blogId);
        return new ResponseResult(resp);
    }

    @PostMapping("/update")
    public ResponseResult update(Blog blog){
        blogService.update(blog);
        return new ResponseResult();
    }

    @PostMapping("/deleteBlogImg")
    public ResponseResult deleteBlogImg(int imgId){
        blogService.deleteImg(imgId);
        return new ResponseResult();
    }
}
